home *** CD-ROM | disk | FTP | other *** search
Wrap
Imports NCTDISCRIPPERLib.AudioCDRipperClass Public Class Form1 Inherits System.Windows.Forms.Form Dim flgPlay As Boolean Dim flgPause As Boolean Dim BufferSize As Long Dim StartSamples As Long Dim SliderBusy As Boolean Dim RipCount As Long Dim RipCurrent As Long Public cddbSource As Long Public mRipModePreset As Long Public m_Format As Long Public m_Bitrate As Long Public StopRip As Boolean Dim frmProgress As New Form2() Public WithEvents AudioCDRipper1 As NCTDISCRIPPERLib.AudioCDRipperClass #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar Friend WithEvents Panel1 As System.Windows.Forms.Panel Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar Friend WithEvents StatusBarPanel1 As System.Windows.Forms.StatusBarPanel Friend WithEvents StatusBarPanel2 As System.Windows.Forms.StatusBarPanel Friend WithEvents StatusBarPanel3 As System.Windows.Forms.StatusBarPanel Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader Friend WithEvents ToolBarButton10 As System.Windows.Forms.ToolBarButton Friend WithEvents StatusBarPanel4 As System.Windows.Forms.StatusBarPanel Friend WithEvents cbDrive As System.Windows.Forms.ComboBox Friend WithEvents txtAlbum As System.Windows.Forms.TextBox Friend WithEvents txtArtist As System.Windows.Forms.TextBox Friend WithEvents lvTracks As System.Windows.Forms.ListView Friend WithEvents btnGetCDDB As System.Windows.Forms.ToolBarButton Friend WithEvents btnRipNow As System.Windows.Forms.ToolBarButton Friend WithEvents btnRefreshCD As System.Windows.Forms.ToolBarButton Friend WithEvents btnEject As System.Windows.Forms.ToolBarButton Friend WithEvents ImageList1 As System.Windows.Forms.ImageList <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.ToolBar1 = New System.Windows.Forms.ToolBar() Me.ToolBarButton10 = New System.Windows.Forms.ToolBarButton() Me.btnEject = New System.Windows.Forms.ToolBarButton() Me.btnRefreshCD = New System.Windows.Forms.ToolBarButton() Me.btnGetCDDB = New System.Windows.Forms.ToolBarButton() Me.btnRipNow = New System.Windows.Forms.ToolBarButton() Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components) Me.Panel1 = New System.Windows.Forms.Panel() Me.txtAlbum = New System.Windows.Forms.TextBox() Me.txtArtist = New System.Windows.Forms.TextBox() Me.cbDrive = New System.Windows.Forms.ComboBox() Me.StatusBar1 = New System.Windows.Forms.StatusBar() Me.StatusBarPanel4 = New System.Windows.Forms.StatusBarPanel() Me.StatusBarPanel1 = New System.Windows.Forms.StatusBarPanel() Me.StatusBarPanel2 = New System.Windows.Forms.StatusBarPanel() Me.StatusBarPanel3 = New System.Windows.Forms.StatusBarPanel() Me.lvTracks = New System.Windows.Forms.ListView() Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader() Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader() Me.Panel1.SuspendLayout() CType(Me.StatusBarPanel4, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.StatusBarPanel2, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.StatusBarPanel3, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'ToolBar1 ' Me.ToolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton10, Me.btnEject, Me.btnRefreshCD, Me.btnGetCDDB, Me.btnRipNow}) Me.ToolBar1.DropDownArrows = True Me.ToolBar1.ImageList = Me.ImageList1 Me.ToolBar1.Name = "ToolBar1" Me.ToolBar1.ShowToolTips = True Me.ToolBar1.Size = New System.Drawing.Size(600, 55) Me.ToolBar1.TabIndex = 0 ' 'ToolBarButton10 ' Me.ToolBarButton10.Style = System.Windows.Forms.ToolBarButtonStyle.Separator ' 'btnEject ' Me.btnEject.ImageIndex = 0 Me.btnEject.Tag = "0" Me.btnEject.Text = "Eject" ' 'btnRefreshCD ' Me.btnRefreshCD.ImageIndex = 1 Me.btnRefreshCD.Tag = "1" Me.btnRefreshCD.Text = "Refresh CD" ' 'btnGetCDDB ' Me.btnGetCDDB.ImageIndex = 2 Me.btnGetCDDB.Tag = "2" Me.btnGetCDDB.Text = "Get CDDB" ' 'btnRipNow ' Me.btnRipNow.ImageIndex = 3 Me.btnRipNow.Tag = "3" Me.btnRipNow.Text = "Rip Now" ' 'ImageList1 ' Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit Me.ImageList1.ImageSize = New System.Drawing.Size(32, 32) Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer) Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent ' 'Panel1 ' Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtAlbum, Me.txtArtist, Me.cbDrive}) Me.Panel1.Dock = System.Windows.Forms.DockStyle.Top Me.Panel1.Location = New System.Drawing.Point(0, 55) Me.Panel1.Name = "Panel1" Me.Panel1.Size = New System.Drawing.Size(600, 42) Me.Panel1.TabIndex = 1 ' 'txtAlbum ' Me.txtAlbum.Dock = System.Windows.Forms.DockStyle.Fill Me.txtAlbum.Location = New System.Drawing.Point(0, 21) Me.txtAlbum.Name = "txtAlbum" Me.txtAlbum.Size = New System.Drawing.Size(304, 20) Me.txtAlbum.TabIndex = 1 Me.txtAlbum.Text = "" ' 'txtArtist ' Me.txtArtist.Dock = System.Windows.Forms.DockStyle.Right Me.txtArtist.Location = New System.Drawing.Point(304, 21) Me.txtArtist.Name = "txtArtist" Me.txtArtist.Size = New System.Drawing.Size(296, 20) Me.txtArtist.TabIndex = 2 Me.txtArtist.Text = "" ' 'cbDrive ' Me.cbDrive.Dock = System.Windows.Forms.DockStyle.Top Me.cbDrive.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList Me.cbDrive.Name = "cbDrive" Me.cbDrive.Size = New System.Drawing.Size(600, 21) Me.cbDrive.TabIndex = 0 ' 'StatusBar1 ' Me.StatusBar1.Location = New System.Drawing.Point(0, 337) Me.StatusBar1.Name = "StatusBar1" Me.StatusBar1.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.StatusBarPanel4, Me.StatusBarPanel1, Me.StatusBarPanel2, Me.StatusBarPanel3}) Me.StatusBar1.ShowPanels = True Me.StatusBar1.Size = New System.Drawing.Size(600, 16) Me.StatusBar1.TabIndex = 2 Me.StatusBar1.Text = "StatusBar1" ' 'StatusBarPanel4 ' Me.StatusBarPanel4.Width = 50 ' 'StatusBarPanel1 ' Me.StatusBarPanel1.Width = 150 ' 'StatusBarPanel2 ' Me.StatusBarPanel2.Width = 150 ' 'StatusBarPanel3 ' Me.StatusBarPanel3.Width = 300 ' 'lvTracks ' Me.lvTracks.CheckBoxes = True Me.lvTracks.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2}) Me.lvTracks.Dock = System.Windows.Forms.DockStyle.Fill Me.lvTracks.FullRowSelect = True Me.lvTracks.GridLines = True Me.lvTracks.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable Me.lvTracks.HideSelection = False Me.lvTracks.Location = New System.Drawing.Point(0, 97) Me.lvTracks.Name = "lvTracks" Me.lvTracks.Size = New System.Drawing.Size(600, 240) Me.lvTracks.TabIndex = 3 Me.lvTracks.View = System.Windows.Forms.View.Details ' 'ColumnHeader1 ' Me.ColumnHeader1.Text = "Track" Me.ColumnHeader1.Width = 400 ' 'ColumnHeader2 ' Me.ColumnHeader2.Text = "Duration" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(600, 353) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lvTracks, Me.StatusBar1, Me.Panel1, Me.ToolBar1}) Me.Name = "Form1" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Test VB.Net NCTDiscRipper ActiveX DLL" Me.Panel1.ResumeLayout(False) CType(Me.StatusBarPanel4, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.StatusBarPanel2, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.StatusBarPanel3, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cddbSource = 0 mRipModePreset = 1 m_Format = 0 m_Bitrate = 0 AudioCDRipper1 = New NCTDISCRIPPERLib.AudioCDRipperClass() AudioCDRipper1.DriverOpen() frmProgress.form = Me RefreshCD() StatusBar1.Panels(3).Text = "CDDB Status: IDLE" End Sub Private Sub PLEnable(ByVal Enable As Boolean) lvTracks.Enabled = Enable End Sub Private Sub RefreshCD() Dim i As Integer StatusBar1.Panels(0).Text = "RefreshCD" PLEnable(False) TBBtnEnable(False) AudioCDRipper1.Refresh() 'Re-read CD drive cbDrive.Items.Clear() For i = 1 To AudioCDRipper1.driveCount AudioCDRipper1.driveNum = i cbDrive.Items.Add("(" & AudioCDRipper1.driveLetter & "\) " & AudioCDRipper1.driveName) Next i If (cbDrive.Items.Count > 0) Then cbDrive.SelectedIndex = 0 cbDrive_SelectedIndexChanged(Nothing, Nothing) End If ReloadInfo() StatusBar1.Panels(0).Text = "Ready" Select Case (AudioCDRipper1.cdType) Case NCTDISCRIPPERLib.CDDiskTypeConstants.REDBOOK : StatusBar1.Panels(1).Text = "CD-DA (Audio Disk)" Case NCTDISCRIPPERLib.CDDiskTypeConstants.YELLOWBOOK : StatusBar1.Panels(1).Text = "Data CD" Case NCTDISCRIPPERLib.CDDiskTypeConstants.ORANGEBOOK : StatusBar1.Panels(1).Text = "Data CD" Case NCTDISCRIPPERLib.CDDiskTypeConstants.GREENBOOK : StatusBar1.Panels(1).Text = "CD-Interactive" Case NCTDISCRIPPERLib.CDDiskTypeConstants.BLUEBOOK : StatusBar1.Panels(1).Text = "CD-Extra" Case NCTDISCRIPPERLib.CDDiskTypeConstants.UNRECOGNIZED : StatusBar1.Panels(1).Text = "No Disk" End Select StatusBar1.Panels(2).Text = "CDDB Disk ID: " & Hex(AudioCDRipper1.cdID) StatusBar1.Panels(3).Text = "CDDB Status: IDLE" End Sub Private Function MyIntToString(ByVal Number As Integer) As String If (Number > 9) Then Return Number Return "0" & Number End Function Private Sub ReloadInfo() Dim i As Integer PLEnable(False) TBBtnEnable(False) AudioCDRipper1.GetCDDBInfo(NCTDISCRIPPERLib.CDDBSourceConstants.CDPLAYERINI) txtAlbum.Text = AudioCDRipper1.cddbInfoAlbum txtArtist.Text = AudioCDRipper1.cddbInfoArtist If (txtArtist.Text.Length() < 1) Then txtArtist.Text = "Unknown Artist" If (txtAlbum.Text.Length() < 1) Then txtAlbum.Text = "Unknown Album" lvTracks.BeginUpdate() lvTracks.Items.Clear() ' lvTracks.Items.Count = AudioCDRipper1.trackCount If (AudioCDRipper1.trackCount <> 0) Then For i = 1 To AudioCDRipper1.trackCount AudioCDRipper1.trackNum = i Dim li As ListViewItem If (AudioCDRipper1.cddbInfoTitle.Length() > 0) Then li = lvTracks.Items.Add(MyIntToString(i) & " " & AudioCDRipper1.cddbInfoTitle) Else li = lvTracks.Items.Add("Track " & MyIntToString(i)) End If li.Checked = True Dim min As Long = AudioCDRipper1.trackDuration \ 60000 Dim sec As Long = AudioCDRipper1.trackDuration \ 1000 - min * 60 li.SubItems.Add(MyIntToString(min) + ":" + MyIntToString(sec)) Next AudioCDRipper1.trackNum = 1 lvTracks.Items(0).Focused = True PLEnable(True) TBBtnEnable(True) Else TBBtnEnable(True) btnGetCDDB.Enabled = False btnRipNow.Enabled = False PLEnable(False) End If lvTracks.EndUpdate() End Sub Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick Select Case e.Button.Tag Case 0 : AudioCDRipper1.Eject() Case 1 : RefreshCD() Case 2 Dim CDDBInfoEnabled As Boolean Select Case (cddbSource) Case 1 : CDDBInfoEnabled = AudioCDRipper1.GetCDDBInfo(NCTDISCRIPPERLib.CDDBSourceConstants.ONLINEDATABASE) Case 2 : CDDBInfoEnabled = AudioCDRipper1.GetCDDBInfo(NCTDISCRIPPERLib.CDDBSourceConstants.CDPLAYERINI) Case Else : CDDBInfoEnabled = AudioCDRipper1.GetCDDBInfo(NCTDISCRIPPERLib.CDDBSourceConstants.ALL) End Select If (CDDBInfoEnabled) Then txtAlbum.Text = AudioCDRipper1.cddbInfoAlbum txtArtist.Text = AudioCDRipper1.cddbInfoArtist ReloadInfo() Else MsgBox("No CDDB Information available! Try other CDDB source.") End If StatusBar1.Panels(3).Text = "CDDB Status: IDLE" Case 3 : RipNow() End Select End Sub Private Sub TBBtnEnable(ByVal Enable As Boolean) btnEject.Enabled = Enable btnRefreshCD.Enabled = Enable btnGetCDDB.Enabled = Enable btnRipNow.Enabled = Enable End Sub Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed AudioCDRipper1.DriverClose() frmProgress.Dispose() End Sub Private Sub RipNow() Dim i As Int16 PLEnable(False) TBBtnEnable(False) Dim Rip As New Collection() Dim gl As RipList RipCount = 0 For i = 0 To lvTracks.Items.Count - 1 If (lvTracks.Items(i).Checked) Then gl = New RipList() gl.TracNum = i + 1 gl.FileName = lvTracks.Items(i).Text RipCount += 1 Rip.Add(gl) End If Next i If (RipCount < 1) Then MsgBox("No files to rip.") PLEnable(True) TBBtnEnable(True) Return End If Refresh() frmProgress.pb1.Value = 0 frmProgress.Show() frmProgress.Refresh() StopRip = False AudioCDRipper1.ripModePreset = mRipModePreset BufferSize = 44100 / 4 For i = 1 To Rip.Count If (StopRip) Then Exit For RipCurrent = i gl = Rip(i) AudioCDRipper1.trackNum = gl.TracNum 'Rip To WAV frmProgress.FileName = gl.FileName & ".wav" & " Format: 44KHz, 16Bit, Stereo" frmProgress.pb1.Value = 0 AudioCDRipper1.RipTrackToWav(gl.FileName) While frmProgress.pb1.Value <> 100 Application.DoEvents() End While 'Rip To MP3 AudioCDRipper1.SetFormatMP3() frmProgress.pb1.Value = 0 frmProgress.FileName = gl.FileName & ".mp3" & " Format: " & AudioCDRipper1.trackFormatString AudioCDRipper1.RipTrackToMP3(gl.FileName) While frmProgress.pb1.Value <> 100 Application.DoEvents() End While 'Rip To WMA AudioCDRipper1.SetFormatWMA() frmProgress.pb1.Value = 0 frmProgress.FileName = gl.FileName & ".wma" & " Format: " & AudioCDRipper1.trackFormatString AudioCDRipper1.RipTrackToWMA(gl.FileName) While frmProgress.pb1.Value <> 100 Application.DoEvents() End While Next For i = 1 To Rip.Count Rip.Remove(1) Next frmProgress.Hide() PLEnable(True) TBBtnEnable(True) End Sub Private Sub AudioCDRipper1_CDDBQueryStatus(ByVal Status As NCTDISCRIPPERLib.CDDBQueryStatusConstants) Handles AudioCDRipper1.CDDBQueryStatus Select Case (Status) Case NCTDISCRIPPERLib.CDDBQueryStatusConstants.QUERY : StatusBar1.Panels(3).Text = "CDDB Status: QUERY" Case NCTDISCRIPPERLib.CDDBQueryStatusConstants.PROCESSANSWER : StatusBar1.Panels(3).Text = "CDDB Status: PROCESS ANSWER" End Select End Sub Private Sub AudioCDRipper1_RipRetry(ByVal sender As System.Object, ByVal e As System.EventArgs) frmProgress.DrawTextMy("Read or Synch Error! Retry.") Application.DoEvents() 'Yields execution so that operating system could produce the other events If (StopRip) Then AudioCDRipper1.StopRip() End Sub Private Sub AudioCDRipper1_RipProgress(ByVal Percent As Integer) Handles AudioCDRipper1.RipProgress frmProgress.DrawTextMy("") frmProgress.pb1.Value = Percent If (StopRip) Then AudioCDRipper1.StopRip() End Sub Private Sub AudioCDRipper1_MediaChange() Handles AudioCDRipper1.MediaChange RefreshCD() End Sub Private Sub cbDrive_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbDrive.SelectedIndexChanged AudioCDRipper1.driveNum = cbDrive.SelectedIndex + 1 End Sub End Class